package kr.co.cherryt.view;

import kr.co.cherryt.cherryt.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;

public class GalleryNavigator extends View {
    private static final int SPACING = 6;
    private static final int RADIUS = 4;
    private int mSize = 5;
    private int mPosition = 0;
    private static final Paint mOnPaint = new Paint(Paint.ANTI_ALIAS_FLAG);;
    private static final Paint mOffPaint = new Paint(Paint.ANTI_ALIAS_FLAG);;

    private Context mContext;
    private Bitmap mPageNormalBmp = null;
    private Bitmap mPageSelectBmp = null;

    public GalleryNavigator(Context context) {
        super(context);
        mOnPaint.setColor(0xCCFF0000);
        mOffPaint.setColor(0x660000FF);
        mContext = context;
        init();
    }

    public GalleryNavigator(Context context, int size) {
        this(context);
        mSize = size;
        mContext = context;
        init();
    }

    public GalleryNavigator(Context context, AttributeSet attrs) {
        super(context, attrs);
        mOnPaint.setColor(0xCCFF0000);
        mOffPaint.setColor(0x660000FF);
        mContext = context;
        init();
    }

	void init() {
		mPageNormalBmp = BitmapFactory.decodeResource( mContext.getResources(), R.drawable.page_normal );
		mPageSelectBmp = BitmapFactory.decodeResource( mContext.getResources(), R.drawable.page_select );
	}
    
    @Override
    protected void onDraw(Canvas canvas) {
    	Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
    	
    	for (int i = 0; i < mSize; ++i) {
    		if (i == mPosition) {
            	int x = i * 15;
                canvas.drawBitmap( mPageSelectBmp, x, 0, paint);
            } else {
            	int x = i * 15;
                canvas.drawBitmap( mPageNormalBmp, x, 0, paint);
            }
//    		paint.setColor(0xC0900000);
//			if (i == mPosition) {
//	        	int x = i * 15;
//	            canvas.drawCircle(x+7, 10, 5, paint);
//	        } else {
//	        	int x = i * 15;
//	        	canvas.drawCircle(x+7, 10, 2, paint);
//	        }
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    	setMeasuredDimension(mSize * (15), 50);
    }
    
	public void setPosition(int id) {
        mPosition = id;
    }

    public void setSize(int size) {
        mSize = size;
        requestLayout();
    }

    public void setPaints(int onColor, int offColor) {
        mOnPaint.setColor(onColor);
        mOffPaint.setColor(offColor);
    }

    public void setBlack() {
        setPaints(0xE6000000, 0x66000000);
    }
}
